Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Commit 6e10b7c45787d0be4c4a9e17622aeb5f4a888287


Parents : e119276
Author : Ivan <ivan@quad4.io>
Signature : Signature validation error
Date : 2026-04-27T11:58:53-05:00

refactor(audio): encapsulate audio record creation and permission check in TelephoneNativeAudioSession and WavPcmAttachmentRecorder

Changes
Diff

diff --git a/android/app/src/main/java/com/meshchatx/TelephoneNativeAudioSession.java b/android/app/src/main/java/com/meshchatx/TelephoneNativeAudioSession.java
index a636bfbe..838810b8 100644
--- a/android/app/src/main/java/com/meshchatx/TelephoneNativeAudioSession.java
+++ b/android/app/src/main/java/com/meshchatx/TelephoneNativeAudioSession.java
@@ -240,13 +240,11 @@ public final class TelephoneNativeAudioSession {
AudioRecord.getMinBufferSize(SAMPLE_RATE, IN_CHANNEL, FORMAT),
4096
);
- audioRecord = new AudioRecord(
- MediaRecorder.AudioSource.VOICE_COMMUNICATION,
- SAMPLE_RATE,
- IN_CHANNEL,
- FORMAT,
- inBuf * 2
- );
+ audioRecord = createVoiceAudioRecord(inBuf);
+ if (audioRecord == null) {
+ postDispatch("error", "no_record_audio_permission", null);
+ return;
+ }
if (audioRecord.getState() != AudioRecord.STATE_INITIALIZED) {
releaseTx();
postDispatch("error", "record_init", null);
@@ -307,6 +305,20 @@ public final class TelephoneNativeAudioSession {
}
}
+ @Nullable
+ private AudioRecord createVoiceAudioRecord(int inBuf) {
+ if (ContextCompat.checkSelfPermission(appContext, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
+ return null;
+ }
+ return new AudioRecord(
+ MediaRecorder.AudioSource.VOICE_COMMUNICATION,
+ SAMPLE_RATE,
+ IN_CHANNEL,
+ FORMAT,
+ inBuf * 2
+ );
+ }
+
private void drainMicrophone() {
byte[] buf = new byte[4096];
while (running.get() && webSocket != null) {

diff --git a/android/app/src/main/java/com/meshchatx/WavPcmAttachmentRecorder.java b/android/app/src/main/java/com/meshchatx/WavPcmAttachmentRecorder.java
index 2b398cb7..f13e5ad1 100644
--- a/android/app/src/main/java/com/meshchatx/WavPcmAttachmentRecorder.java
+++ b/android/app/src/main/java/com/meshchatx/WavPcmAttachmentRecorder.java
@@ -49,7 +49,7 @@ public final class WavPcmAttachmentRecorder {
if (rec.get()) {
return "err: already recording";
}
- if (!canStart(ctx)) {
+ if (ContextCompat.checkSelfPermission(ctx, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
return "err: record_audio";
}
int min = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL, ENCODING);


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────